package com.qf.ym.service;

import com.qf.ym.mapper.AdminMapper;
import com.qf.ym.entity.AdminEntity;
import com.qf.ym.pojo.AdminPojo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AdminServiceImpl implements AdminService {

    @Autowired
    AdminMapper adminMapper;


    @Override
    public AdminPojo adminLogin(AdminEntity ae) {

        return adminMapper.adminLogin(ae);
    }

    @Override
    public AdminPojo adminQuery(AdminEntity ae) {
        return adminMapper.adminLogin(ae);
    }


    @Override
    public List<AdminPojo> adminList(AdminEntity ae) {
        return adminMapper.adminList(ae);
    }

    @Override
    public boolean delAdmin(Integer aid) {
  //删除单个aid对应的用户值
        String str="("+aid+")";
        return adminMapper.delAdmin(str);
    }

    public boolean delAdminByids(String aids){
        String str="("+aids.substring(0, aids.length()-1)+")";
        return adminMapper.delAdmin(str);
    }
    //添加绑定用户
    @Override
    public boolean adminAdd(AdminEntity ae) {
        boolean add = adminMapper.adminAdd(ae);
        if(add){
            String[] roles = ae.getRoles();
            for(String rid:roles){
                         adminMapper.bindAdminRole(ae.getAid(),Integer.parseInt(rid));
            }

        }
        return true;
    }
    //修改管理员信息
    @Override
    public boolean editAdmin(AdminEntity ae) {
         adminMapper.editAdmin(ae);

         adminMapper.deleteAdminRoles(ae);

         for (String ro:ae.getRoles()){
             adminMapper.bindAdminRole(ae.getAid(),Integer.parseInt(ro));
         }

         return true;
    }
    //启用
    @Override
    public boolean qiyongAdmin(AdminEntity ae) {
        return adminMapper.editAdmin(ae);
    }

}
